package com.gewu.pm.widget;

import android.content.Context;
import android.util.AttributeSet;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

/**
 * 完全展开的RecyclerView
 * 解决在ScrollView中高度不自适应的问题
 */
public class FullyExpandedRecyclerView extends RecyclerView {

    public FullyExpandedRecyclerView(@NonNull Context context) {
        super(context);
    }

    public FullyExpandedRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public FullyExpandedRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onMeasure(int widthSpec, int heightSpec) {
        // 重新计算高度为 AT_MOST，让RecyclerView完全展开显示所有Item
        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        super.onMeasure(widthSpec, expandSpec);
    }
}

